<template>
	<view class="crm">
		<!-- <u-sticky> -->
		<view class="tops1">
			<view class="searchBox">
				<view class="search">
					<view class="inp">
						<u-search @change="changeInpFn"  :clearabled="true"  @clear="search" @search="search" bg-color="#fff" :show-action="false" height="60" search-icon=""
							placeholder-color="rgba(15, 20, 23, 0.3)" placeholder="请输入订单号" v-model="keyword">
						</u-search>
					</view>
					<view class="btns" @click="search">
						搜索
					</view>
				</view>

			</view>
			<view class="calcuTotal">
				<view class="left">
					<view class="num">
						<!-- {{addData.totalCount}} -->
						<u-count-to bold color="#0F1417" font-size="34" :end-val="addData.totalCount" separator=","></u-count-to>
					</view>
					<view class="desc">
						订单总数
					</view>
				</view>
				<view class="lines">

				</view>
				<view class="right">
					<view class="num">
						<!-- {{addData.totalAmount}} -->
						<u-count-to bold color="#0F1417" font-size="34" :end-val="addData.totalAmount" separator=","></u-count-to>
					</view>
					<view class="desc">
						总金额（元）
					</view>
				</view>
			</view>
			<view class="selectOptions">
				
				<view class="right" >
				<!-- 	{{!time?"全部日期":time}}
					<u-icon v-if="!time" class="u-m-l-8" name="arrow-down-fill" color="#FA4A53" size="24"></u-icon>
					<u-icon @click="time=''" v-else class="u-m-l-8" name="close-circle-fill" color="#FA4A53" size="24"></u-icon>
					 -->
					
					<view @click="show=true" v-if="!time" class="">
						全部日期
						<u-icon  class="u-m-l-8" name="arrow-down-fill" color="#FA4A53" size="24"></u-icon>
					</view>
					<view  @click="clearTime" v-else class="">
						
						
						{{time}}
						<u-icon class="u-m-l-8" name="close-circle-fill" color="#FA4A53" size="24"></u-icon>
					</view>
					
				
					<!-- <u-icon class="u-m-l-8" name="arrow-down-fill" color="#FA4A53" size="24"></u-icon> -->
				</view>
				
				<!-- <view class="right" @click="show=true">
					{{!time?"全部日期":time}}
					<u-icon class="u-m-l-8" name="arrow-down-fill" color="#FA4A53" size="24"></u-icon>
				</view> -->
			</view>

		</view>
		<view v-if="list1.length" class="list" :style="{'padding-top': paddingTop}">
			<view class="item" v-for="(item,index) in list1" @click="godetail(item)">
				<view class="sameStyle">
					<view class="left">
						<text>{{item.orderNo}}</text>
						
					</view>
					<view style="color: #FA4A53;" class="right">
						<text>￥</text>
						{{item.totalPayableAmount}}
					</view>

				</view>
				<view class="u-m-t-10 sameStyle bot">
					<view class="left">
						<text>{{item.orderContent}}</text>
					</view>
					<view class="right">
						{{item.buyerMobile}}
					</view>

				</view>

			</view>
			<uni-load-more :status="status"></uni-load-more>
		</view>
		<view v-else class="empty" style="padding-top: 150px;">
			<view v-if="!list1.length && senDate" class="emptyAddress-box">
				<u-empty text="暂无内容" mode="news"></u-empty>
			</view>
		</view>

		<u-calendar
		active-bg-color="#FA4A53"	
		btn-type="error"
		range-color="rgba(250, 74, 83, 0.4)"
		 active-color="#fff" v-model="show" mode="range" @change="change"></u-calendar>
	</view>
</template>

<script>
	import piaoyiSelect from '@/uni_modules/piaoyi-select/components/piaoyi-select/piaoyi-select.vue'

	export default {
		components: {
			piaoyiSelect
		},

		data() {
			return {
				addData:null,
				time:'',
				show: false,
				clearable: false,
				filterable: false,
				inputValue: '',

				barStyle: {
					'width': '96rpx',
					'height': '4rpx',
					'background': 'linear-gradient( 211deg, #EF8548 0%, #DE4543 100%)'
				},
				claName: '',
				checkAll: false,
				curId: '',
				curPhone: '',
				transferPhone: '',
				transferToAppMask: false,
				total: null, //总共多少条数据
				formData: {
					pageSize: 10, //每页10条数据
					page: 1, //第几页
					status: "",
				},

				status: "more",
				senDate: false,
				list1: [],

				keyword: '',
			
				paddingTop: "",
				entityCount: '',
				startDate:"",
				endDate:""

			}
		},
		onReady() {
			uni.createSelectorQuery().select('.tops1').boundingClientRect((rect) => {
				console.log(rect.height, 66666);
				this.paddingTop = rect.height + 'px'
			}).exec()
		},
		onLoad() {

			this.getlist()

		},
		onReachBottom() {
			let allTotal = this.formData.page * this.formData.pageSize;
			if (allTotal < this.total) {
				//当前条数小于总条数 则增加请求页数
				this.status = "loading"; //加载中状态
				this.formData.page++;
				this.getlist();
			} else {
				this.status = "noMore"; //加载完状态
				console.log("已加载全部数据");
			}
		},
		onPullDownRefresh() {
			this.formData.page = 1;
			// this.list1 = [];
			this.getlist('fresh');
		},
		methods: {
			changeInpFn(e){
				
				if(e==''){
					this.formData.page = 1;
					this.getlist('fresh');
				}
				
			},
			
			
			clearTime(){
				 this.time=''
				 this.startDate = ''
				 this.endDate = ''
				 this.getlist('fresh');
			},
			change(e) {
				console.log(e);
				this.time = e.startDate+"~"+e.endDate
				this.startDate =  e.startDate
				this.endDate = e.endDate
				// this.formData.page = 1;
				// this.list1 = [];
				// this.getlist();
				
				this.formData.page = 1;
				this.getlist('fresh');

			},
			// 状态：ENABLE正常，EXPIRE已过期，DISABLE已停用
			GetcardTypeCodeColor(item) {
				if (item.status == 'ENABLE') {
					return 'base'
				} else if (item.status == 'EXPIRE') {
					return 'ending'
				} else {
					return 'over'
				}
			},
			
			search() {
				// this.formData.page = 1
				// this.list1 = []
				// this.getlist()
				this.formData.page = 1;
				this.getlist('fresh');
			},
			getlist(type) {
				this.senDate = false;
				let query = {
					pageIndex: this.formData.page,
					pageSize: this.formData.pageSize,
					type:"SOFT",
					orderNo:this.keyword,
					startDate: this.startDate,
					endDate:this.endDate
				}

				this.$u.api
					.orderPageOrder(query)
					.then((res) => {
						if(type=='fresh'){
							this.list1 = [];
						}
						this.senDate = true;
						if (res.code == 'ok') {
							this.addData =  res?.data?.addData
							this.entityCount = res?.data?.entityCount
							this.total = res.data.entityCount;
							const newlist = res.data.entities;
							this.list1.push(...newlist);
							if (this.list1.length < this.formData.pageSize) {
								this.status = "noMore"; //加载完状态
							}
						} else {}
						uni.stopPullDownRefresh()
						uni.hideLoading();
					});
			},

			godetail(e) {
				uni.navigateTo({
					url: "/subPack/order/detail?id=" + e.orderNo
				})
			}
		}
	}
</script>

<style>
	page {
		background: #fff;
	}
</style>
<style scoped lang="scss">
	.crm {
		padding: 0 0 24rpx;

		.calcuTotal {
			padding: 30rpx 0 0rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left,
			.right {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				flex: 1;

				.num {
					font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
					font-weight: 600;
					font-size: 34rpx;
					color: #0F1417;
					line-height: 38rpx;
				}

				.desc {
					margin-top: 8rpx;
					font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
					font-weight: 400;
					font-size: 24rpx;
					color: #4E5969;
					line-height: 28rpx;
				}
			}

			.lines {
				width: 2rpx;
				height: 60rpx;
				background: #E7E7E7;
			}
		}

		.tops1 {
			background: #FFFFFF;
			padding: 24rpx 0 0;
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			z-index: 9;
		}

		.selectOptions {
			border-bottom: 2rpx solid #E7E7E7;
			padding: 20rpx 40rpx 14rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			.right {
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
				font-weight: 400;
				font-size: 24rpx;
				color: #FA4A53;
				line-height: 28rpx;

				text {
					color: #0F1417;
				}
			}
		}

		.list {

			padding: 0 40rpx;

			.item {
				padding: 26rpx 0;
				border-bottom: 2rpx solid #F6F6F6;

				// margin-bottom:24rpx;
				// padding: 0 24rpx;
				// background: #FFFFFF;
				// border-radius: 16rpx 16rpx 16rpx 16rpx;
				.sameStyle {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.left {
						font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
						font-weight: 500;
						font-size: 28rpx;
						color: #0F1417;
						line-height: 40rpx;

						.status {
							padding-left: 16rpx;
							font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
							font-weight: 500;
							font-size: 28rpx;
							color: #6F7274;
							line-height: 33rpx;

							&.add {
								color: rgba(23, 103, 222, 1) !important;
							}

							&.doing {
								color: #FFA340 !important;
							}

							&.ok {
								color: #1BAB6B !important;
							}
						}
					}

					.right {
						display: flex;
						align-items: flex-end;
						font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
						font-weight: 500;
						font-size: 32rpx;
						color: #0F1417;
						line-height: 44rpx;

						text {
							font-size: 24rpx;
						}
					}

				}

				.bot {

					.left,
					.right {
						font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
						font-weight: 400;
						font-size: 24rpx;
						color: rgba(15, 20, 23, 0.4) !important;
						line-height: 28rpx;
					}
				}

			}
		}


		.tags {
			font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
			font-weight: 400;
			font-size: 20rpx;
			margin-left: 8rpx;
			line-height: 20rpx;
			padding: 4rpx 10rpx;
			border-radius: 14rpx 14rpx 14rpx 14rpx;
			color: #fff;

			&.base {
				color: #FFFFFF !important;
				background: #1BAB6B !important;
			}

			&.over {
				// color: #FFE1CF !important;
				background: #6F7274 !important;
			}

			&.ending {
				color: #FFE1CF !important;
				background: #FA4A53 !important;
			}


		}


		.borderGap {
			// margin-bottom: 8rpx;
			border-bottom: 2rpx solid #E7E7E7;
			margin-top: -4rpx;

		}

		.searchBox {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 0 32rpx 0;
		}

		.search {
			flex: 1;

			height: 64rpx;
			background: #FFFFFF;
			border-radius: 152rpx 152rpx 152rpx 152rpx;
			border: 2rpx solid #FA4A53;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.inp {
				flex: 1;
			}

			.btns {
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
				font-weight: 400;
				font-size: 24rpx;
				color: #FFFFFF;
				line-height: 40rpx;
				margin: 4rpx;
				width: 128rpx;
				height: 56rpx;
				background: #FA4A53;
				border-radius: 152rpx 152rpx 152rpx 152rpx;
			}
		}

	}
</style>
